package com.ruihu.admin.module.business.electric.config.service;

import com.ruihu.admin.common.constant.ResponseCodeConst;
import com.ruihu.admin.common.domain.ResponseDTO;
import com.ruihu.admin.constant.ElectricConfigTypeEnum;
import com.ruihu.admin.module.business.electric.config.dao.ElectricConfigDao;
import com.ruihu.admin.module.business.electric.config.domain.dto.ElectricConfigDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 工厂配置Service
 */
@Service
public class FactoryConfigService {

    @Autowired
    private ElectricConfigDao electricConfigDao;

    /**
     * 根据Code查询电芯类型配置
     * @param code
     * @return
     */
    @Cacheable(value = "getFactoryConfigByCode", key = "T(com.ruihu.admin.constant.RedisConstants).queryFactoryConfigByCodeKey(#code)", condition = "#code != null", unless = "#result.data == null")
    public ResponseDTO<ElectricConfigDTO> getFactoryConfigByCode(String code) {
        ElectricConfigDTO electricConfigDTO = this.electricConfigDao.getElectricConfigByCodeAndConfigType(code, ElectricConfigTypeEnum.FACTORY_CONFIG.getCode());
        if (Objects.nonNull(electricConfigDTO))
            return ResponseDTO.succData(electricConfigDTO);

        return ResponseDTO.wrap(ResponseCodeConst.NOT_EXISTS);
    }
}
